﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using HGZP.BLL;
using HGZP.Model;
using HGZP.PLL;

namespace SZCB.admin.Function
{
    public partial class AddFunction : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                BindIllnessClass();
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            CFunctionDataBLL myCFunctionBLL = new CFunctionDataBLL();
            DataTable dt = myCFunctionBLL.F02_SelectHaveWhere("sName = '" + txtName.Text + "'");
            if (dt.Rows.Count > 0)
            {
                string strErrmessage = "该功效已添加";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }
            if (ddlContentClass.SelectedItem.Text == "----请选择分类----")
            {
                string strErrmessage = "请选择功效大类";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;

            }


            CFunctionData myCFunction = new CFunctionData();
            myCFunction.sGuid = MyFunction.GetNewGuid();
            myCFunction.sName = txtName.Text;
            myCFunction.dCreateDate = DateTime.Now;
            myCFunction.sClassName = ddlContentClass.SelectedItem.Text;
            myCFunction.sClassGuid = ddlContentClass.SelectedValue;
            myCFunction.sBrief = txtBrief.Text;
            if (!myCFunctionBLL.F_Insert(myCFunction))
            {
                string strErrmessage = "添加功效失败";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }

        }

        private void BindIllnessClass()
        {
            CFunctionClassBLL myCFunctionClassBLL = new CFunctionClassBLL();
            ddlContentClass.DataSource = myCFunctionClassBLL.F02_SelectHaveWhere("");
            ddlContentClass.DataTextField = myCFunctionClassBLL.sName;
            ddlContentClass.DataValueField = myCFunctionClassBLL.sGuid;
            ddlContentClass.DataBind();
            ListItem listItem = new ListItem();
            listItem.Text = "----请选功效分类----";
            listItem.Value = "0";
            ddlContentClass.Items.Add(listItem);
            ddlContentClass.SelectedValue = "0";
        }

    }
}